package com.iexbuy.ihg.ui.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.iexbuy.ihg.R;
import com.iexbuy.ihg.common.CommUtil;
import com.iexbuy.ihg.entity.YunDealObject;
import com.iexbuy.ihg.entity.YunItemListObject;
import com.iexbuy.ihg.net.ServiceHelper;
import com.iexbuy.ihg.utils.JsonUtils;
import com.jingchen.pulltorefresh.PullToRefreshLayout;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

import org.w3c.dom.Text;

import java.util.HashMap;

public class YunGuoOrderResultFragment extends BaseFragment {
	
	private static YunGuoOrderResultFragment homeFragmentInstent;

	@ViewInject(R.id.msgListLayout)
	private PullToRefreshLayout msgListRefreshLayout;
	@ViewInject(R.id.listView)
	private ListView listView;

	@ViewInject(R.id.submitResult)
	private TextView submitResult;
	@ViewInject(R.id.itemName)
	private TextView itemName;
	@ViewInject(R.id.itemPrice)
	private TextView itemPrice;
	@ViewInject(R.id.orderTime)
	private TextView orderTime;
	@ViewInject(R.id.payMethod)
	private TextView payMethod;
	@ViewInject(R.id.orderNo)
	private TextView orderNo;

	private static YunItemListObject yunItemListObject;
	private static YunDealObject yunDealObject;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		homeFragmentInstent = this;
	}

	@Override
	protected View _onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_yunguo_order_result, container, false);
		ViewUtils.inject(this, rootView);
		initView(rootView);
		return rootView;
	}

	private void initView(View rootView) {
		mBaseActivity.setTitle(getResources().getString(R.string.yun_guo_order_confirm));
		mBaseActivity.setTitleLayoutVisibility(true);
		mBaseActivity.setHomeActivity(false);

		if ("0".equalsIgnoreCase(yunDealObject.getResultCode())) {
			submitResult.setText("恭喜！参与0购成功！");
		} else {
			submitResult.setText("参与失败！请确认金币是否足够或本期名额是否已满。");
		}
		itemName.setText("第"+yunItemListObject.getPeriod()+"期"+yunDealObject.getItemName());
		itemPrice.setText(yunDealObject.getTransactionCoin()+"个");
		orderTime.setText(yunDealObject.getTime());
		payMethod.setText("金币");
		orderNo.setText(yunDealObject.getOrderId());
	}


	//点击事件响应
	@OnClick(R.id.checkYunguoRecordBtn)
	public void onCheckYunguoRecordBtnClick(View view) {
		YunGuoAttenceRecordsFragment.setYunItemListObject(yunItemListObject);
		CommUtil.openSingleFragmentActivity(mBaseActivity, YunGuoAttenceRecordsFragment.class);
	}

	@OnClick(R.id.continueYunguoBtn)
	public void onContinueYunguoBtnClick(View view) {
		mBaseActivity.finish();
	}


	public static void setYunDealObject(YunDealObject yunDealObject) {
		YunGuoOrderResultFragment.yunDealObject = yunDealObject;
	}

	public static void setYunItemListObject(YunItemListObject yunItemListObject) {
		YunGuoOrderResultFragment.yunItemListObject = yunItemListObject;
	}

	/**
	 * @return the homeFragmentInstent
	 */
	public static YunGuoOrderResultFragment getHomeFragmentInstent() {
		return homeFragmentInstent;
	}

}
